import http from '../api';

export default (state, action) => {
    state = state || {
        blogInfoData: {
            blogId: '',
            blogNm: '',
            blogAuthor: '',
            updateTime: '',
            content: '',
            likeNum: 0,
            isLike: '0',
        }
    };
    switch (action.type) {
        case 'GET_BLOG_INFO':
            return {
                ...state,
                blogInfoData: action.blogInfoData
            }
        case 'LIKE_IT':
            return {
                ...state,
                blogInfoData: {
                    ...state.blogInfoData,
                    likeNum: state.blogInfoData.likeNum + 1
                }
            }
        default:
            return state;
    }
}

export const getBlogInfo = (data) => (dispatch) => {
    http.blog.blogInfo(data).then(res => {
        dispatch({
            type: 'GET_BLOG_INFO',
            blogInfoData: res.data
        })
    })
}
// 点赞
export const likeIt = (data) => (dispatch) => {

    http.blog.like(data).then((res) => {
        if (res.data.msg === 'success') {
            dispatch({ type: 'LIKE_IT' })
        }
    })
}



